package com.ltv.xiangqiplugin.utils;

import java.awt.Color;
import java.awt.Component;
import java.awt.Cursor;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

import com.ltv.xiangqiplugin.models.Messages;
import com.ltv.xiangqiplugin.views.AboutFENView;

public class MessageBox {
	public static int showInformMessage(Component parent, String title, Object message, int messageType) {
		Object[] options = {Messages.getInstance().getProperty("button.ok")};
		return JOptionPane.showOptionDialog(parent,
				message,
				title,
				JOptionPane.OK_OPTION,
				messageType,
				null,
				options,
				null);
	}
	
	public static int showConfirmMessage(Component parent, String title, Object message, int messageType) {
		Object[] options = {Messages.getInstance().getProperty("button.ok"), Messages.getInstance().getProperty("button.cancel")};
		return JOptionPane.showOptionDialog(parent,
				message,
				title,
				JOptionPane.OK_CANCEL_OPTION,
				messageType,
				null,
				options,
				null);
	}
	
	public static void main(String[] args) {
		//showInformMessage(null, "title", "INFORMATION_MESSAGE", JOptionPane.INFORMATION_MESSAGE);
		
		// showInformMessage(null, "title", "ERROR_MESSAGE", JOptionPane.ERROR_MESSAGE);
		
		//showConfirmMessage(null, "title", "INFORMATION_MESSAGE", JOptionPane.INFORMATION_MESSAGE);
		//showConfirmMessage(null, "title", "QUESTION_MESSAGE", JOptionPane.QUESTION_MESSAGE);
		
		
		JTextField fenInput = new JTextField();
		Object[] foo = {getLabelForFENDialog(), fenInput, getButtonForFENDialog()};
		showConfirmMessage(null, "title", foo, JOptionPane.QUESTION_MESSAGE);
	}
	
	private static JLabel getLabelForFENDialog() {
		return new JLabel(Messages.getInstance().getProperty("new_tactic.input_message"));
	}
	
	private static JButton getButtonForFENDialog() {
        JButton button = new JButton("[" + Messages.getInstance().getProperty("new_tactic.what_is_fen") + "]");
        button.setFocusPainted(false);
        button.setMargin(new Insets(0, 0, 0, 0));
        button.setContentAreaFilled(false);
        button.setBorderPainted(false);
        button.setOpaque(false);
        button.setCursor(new Cursor(Cursor.HAND_CURSOR));
        button.setForeground(Color.BLUE);
        
        button.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				JOptionPane.showMessageDialog(null, AboutFENView.getInstance().getLocalPanel());
			}
		});
        
        return button;
	}
}
